<?php
/**
* Class GenerateTranslation into Bo Controller
* @author SillySmart
* @copyright SillySmart
* @package Mvc.Controllers.Bo
* @see Mvc.Controllers.Bo.ControllerProtected
* @see Mvc.Controllers.SiteProtected
* @see Sls.Controllers.Core.SLS_GenericController
* @since 1.0
*
*/
class SLS_BoGenerateTranslation extends SLS_BoControllerProtected
{
	public function action()
	{
		$user = $this->hasAuthorative();
		$xml = $this->getXML();
		$xml = $this->makeMenu($xml);
		$controllersXML = $this->_generic->getControllersXML();
		$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));		
		$action = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Translation']"));		
		
		// Check if bo controller already exist
		if (empty($controller))
		{
			$xml->startTag("errors");
			$xml->addFullTag("error","Back-office controller could not be found. Please follow the following link to create it",true);
			$xml->endTag("errors");
			$xml->addFullTag("error_type","rights",true);
		}
		// If action already exist
		else if (!empty($action))
		{
			$xml->startTag("errors");
			$xml->addFullTag("error","Translation action already exists",true);
			$xml->endTag("errors");			
		}
		// Else, let's generate action
		else 
		{
			$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
			$params = array(0 => array("key" 	=> "reload",
					  				   "value" 	=> "true"),
					  		1 => array("key" 	=> "Controller",
					  				   "value" 	=> $controller),
						 	2 => array("key" 	=> "actionName",
					  				   "value" 	=> "Translation"),
					  		3 => array("key"	=> "token",
					  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
					  		4 => array("key"	=> "indexes",
					  				   "value"	=> "noindex,nofollow")					  			
						    );
			foreach($langs as $lang)
			{
				$tmpParam = array("key" 	=> $lang."-action",
								  "value" 	=> "Translation");
				$tmpTitle = array("key" 	=> $lang."-title",
								  "value" 	=> "Translation");
				array_push($params,$tmpParam);
				array_push($params,$tmpTitle);
			}
			file_get_contents($this->_generic->getFullPath("SLS_Bo",
														  "AddAction",
														  $params,
														  true));
			$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Translation".".controller.php");
			
			
			$action = 	t(2).'$xml = $this->getXML();'."\n".
				        t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
				        t(2).'$xml->startTag("bo_actions");'."\n".
				        t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
				        t(2).'{'."\n".
					        t(3).'$xml->startTag("bo_action");'."\n".
					        	t(4).'foreach($boActions[$i] as $key => $value)'."\n".
					        		t(5).'$xml->addFullTag($key,$value,true);'."\n".
					        t(3).'$xml->endTag("bo_action");'."\n".
				        t(2).'}'."\n".
				        t(2).'$xml->endTag("bo_actions");'."\n\n".
				        t(2).'// Check account rights'."\n".
				        t(2).'$right = SLS_BoRights::isAuthorized("custom","",$this->_generic->getActionId());'."\n".
				        t(2).'if ($right == -1)'."\n".
				        	t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
				        t(2).'else if ($right == 0)'."\n".
				        	t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
				        t(2).'// /Check account rights'."\n\n".				        
				        t(2).'set_time_limit(0);'."\n".
				        t(2).'$xmlController = $this->_generic->getControllersXML();'."\n\n".				        
				        t(2).'// Langs'."\n".
						t(2).'$langObject = $this->_generic->getObjectLang();'."\n".
						t(2).'$langs = $langObject->getSiteLangs();'."\n\n".				        
						t(2).'$xml->startTag("langs");'."\n\n".						
				        t(2).'// Check reload'."\n".
				        t(2).'if ($this->_http->getParam("reload_translate") == "true")'."\n".
				        t(2).'{'."\n".
					        t(3).'// Get the target'."\n".
					        t(3).'$target_id = $this->_http->getParam("target_id");'."\n".
					        t(3).'$xml->addFullTag("target_id",$target_id,true);'."\n\n".				        	
					        t(3).'// Init source file'."\n".
					        t(3).'$fileName = "";'."\n\n".				        	
					        t(3).'// If target_id map to site'."\n".
					        t(3).'if ($target_id == "site")'."\n".
					        	t(4).'$fileName = $this->_generic->getPathConfig("genericLangs")."site";'."\n".
					        t(3).'// Else if map to controller'."\n".
					        t(3).'else if (SLS_String::startsWith($target_id,"c_"))'."\n".
					        t(3).'{'."\n".
						       	t(4).'// Try to get the controller'."\n".
						        t(4).'$result = array_shift($xmlController->getTagsAttributes("//controllers/controller[@id=\'".$target_id."\']",array("name")));'."\n".
						        t(4).'if (!empty($result["attributes"][0]["value"]))'."\n".
						        	t(5).'$fileName = $this->_generic->getPathConfig("actionLangs").$result["attributes"][0]["value"]."/__".$result["attributes"][0]["value"];'."\n".
					        t(3).'}'."\n".
					        t(3).'// Else if map to action'."\n".
					        t(3).'else if (SLS_String::startsWith($target_id,"a_"))'."\n".
					        t(3).'{'."\n".
						        t(4).'// Try to get the controller'."\n".
						        t(4).'$result = array_shift($xmlController->getTagsAttributes("//controllers/controller[scontrollers/scontroller[@id=\'".$target_id."\']]",array("name")));'."\n".
						        t(4).'if (!empty($result["attributes"][0]["value"]))'."\n".
						        t(4).'{'."\n".
							        t(5).'$controllerName = $result["attributes"][0]["value"];'."\n".
							        t(5).'// Try to get the action'."\n".
							        t(5).'$result = array_shift($xmlController->getTagsAttributes("//controllers/controller/scontrollers/scontroller[@id=\'".$target_id."\']",array("name")));'."\n".
							        t(5).'if (!empty($result["attributes"][0]["value"]))'."\n".
							        	t(6).'$fileName = $this->_generic->getPathConfig("actionLangs").$controllerName."/".$result["attributes"][0]["value"];'."\n".
						        t(4).'}'."\n".
					        t(3).'}'."\n\n".				        	
					        t(3).'// If we\'ve found a source file'."\n".
					        t(3).'if (!empty($fileName))'."\n".
					        t(3).'{'."\n".
						        t(4).'$properties = array();'."\n".
						        t(4).'$params = $this->_http->getParams();'."\n".
						        t(4).'foreach($params as $key => $value)'."\n".
						        	t(5).'$params[$key] = SLS_String::trimSlashesFromString($value);'."\n\n".				        		
						        t(4).'foreach($langs as $lang)'."\n".
						        	t(5).'$properties[$lang] = array();'."\n\n".				        		
						        t(4).'foreach($params as $key => $value)'."\n".
						        	t(5).'if (SLS_String::startsWith($key,"LG_"))'."\n".
						        		t(6).'foreach($langs as $lang)'."\n".
						        			t(7).'if (SLS_String::startsWith($key,"LG_".$lang."_"))'."\n".
						        				t(8).'$properties[$lang][SLS_String::substrAfterFirstDelimiter($key,"LG_".$lang."_")] = $value;'."\n".
						        t(4).'$this->setLangProperties($fileName,$properties,$langs);'."\n".
					        t(3).'}'."\n".
				        t(2).'}'."\n\n".						
						t(2).'// Load Generics Langs'."\n".
						t(2).'$xml->startTag("site");'."\n".
						t(2).'$properties = $this->getLangProperties($this->_generic->getPathConfig("genericLangs")."site",$langs);'."\n".
						t(2).'$xml->startTag("properties");'."\n".
						t(2).'foreach($properties as $key => $value)'."\n".
						t(2).'{'."\n".
							t(3).'$xml->startTag("property");'."\n".
							t(3).'$xml->addFullTag("name",$key,true);'."\n".
							t(3).'$xml->startTag("values");'."\n".
							t(3).'foreach($langs as $lang)'."\n".
							t(3).'{'."\n".
								t(4).'$xml->startTag("value");'."\n".
								t(4).'$xml->addFullTag("name",str_replace(\'\"\',\'"\',$value[$lang]),true);'."\n".
								t(4).'$xml->addFullTag("lang",$lang,true);'."\n".
								t(4).'$xml->addFullTag("type",(strlen(str_replace(\'\"\',\'"\',$value[$lang]))>50) ? "textarea" : "input",true);'."\n".
								t(4).'$xml->endTag("value");'."\n".
							t(3).'}'."\n".
							t(3).'$xml->endTag("values");'."\n".
							t(3).'$xml->endTag("property");'."\n".
						t(2).'}'."\n".
						t(2).'$xml->endTag("properties");'."\n".
						t(2).'$xml->endTag("site");'."\n\n".						
						t(2).'// Load Controller Lang'."\n".
						t(2).'$controllers = $xmlController->getTagsAttributes("//controllers/controller[@side=\'user\' and count(@isBo) = 0]",array("name","id"));'."\n".
						t(2).'$xml->startTag("controllers");'."\n".
						t(2).'for($i= 0 ; $i<$count=count($controllers) ; $i++)'."\n".
						t(2).'{'."\n".
							t(3).'$xml->startTag("controller");'."\n".
							t(3).'$xml->addFullTag("name",$controllers[$i]["attributes"][0]["value"],true);'."\n".
							t(3).'$xml->addFullTag("id",$controllers[$i]["attributes"][1]["value"],true);'."\n".
							t(3).'$properties = $this->getLangProperties($this->_generic->getPathConfig("actionLangs").$controllers[$i]["attributes"][0]["value"]."/__".$controllers[$i]["attributes"][0]["value"],$langs);'."\n".
							t(3).'$xml->startTag("properties");'."\n".
							t(3).'foreach($properties as $key => $value)'."\n".
							t(3).'{'."\n".
								t(4).'$xml->startTag("property");'."\n".
								t(4).'$xml->addFullTag("name",$key,true);'."\n".
								t(4).'$xml->startTag("values");'."\n".
								t(4).'foreach($langs as $lang)'."\n".
								t(4).'{'."\n".
									t(5).'$xml->startTag("value");'."\n".
									t(5).'$xml->addFullTag("name",str_replace(\'\"\',\'"\',$value[$lang]),true);'."\n".
									t(5).'$xml->addFullTag("lang",$lang,true);'."\n".
									t(5).'$xml->addFullTag("type",(strlen(str_replace(\'\"\',\'"\',$value[$lang]))>50) ? "textarea" : "input",true);'."\n".
									t(5).'$xml->endTag("value");'."\n".
								t(4).'}'."\n".
								t(4).'$xml->endTag("values");'."\n".
								t(4).'$xml->endTag("property");'."\n".
							t(3).'}'."\n".
							t(3).'$xml->endTag("properties");'."\n\n".							
							t(3).'$actions = $xmlController->getTagsAttributes("//controllers/controller[@name=\'".$controllers[$i]["attributes"][0]["value"]."\']/scontrollers/scontroller",array("name","id"));'."\n".
							t(3).'$xml->startTag("actions");'."\n".
							t(3).'for($j= 0 ; $j<$countJ=count($actions) ; $j++)'."\n".
							t(3).'{'."\n".
								t(4).'$xml->startTag("action");'."\n".
								t(4).'$xml->addFullTag("name",$actions[$j]["attributes"][0]["value"],true);'."\n".
								t(4).'$xml->addFullTag("id",$actions[$j]["attributes"][1]["value"],true);'."\n".
								t(4).'$properties = $this->getLangProperties($this->_generic->getPathConfig("actionLangs").$controllers[$i]["attributes"][0]["value"]."/".$actions[$j]["attributes"][0]["value"],$langs);'."\n".
								t(4).'$xml->startTag("properties");'."\n".
								t(4).'foreach($properties as $key => $value)'."\n".
								t(4).'{'."\n".
									t(5).'$xml->startTag("property");'."\n".
									t(5).'$xml->addFullTag("name",$key,true);'."\n".
									t(5).'$xml->startTag("values");'."\n".
									t(5).'foreach($langs as $lang)'."\n".
									t(5).'{'."\n".
										t(6).'$xml->startTag("value");'."\n".
										t(6).'$xml->addFullTag("name",str_replace(\'\"\',\'"\',$value[$lang]),true);'."\n".
										t(6).'$xml->addFullTag("lang",$lang,true);'."\n".
										t(6).'$xml->addFullTag("type",(strlen(str_replace(\'\"\',\'"\',$value[$lang]))>50) ? "textarea" : "input",true);'."\n".
										t(6).'$xml->endTag("value");'."\n".
									t(5).'}'."\n".
									t(5).'$xml->endTag("values");'."\n".
									t(5).'$xml->endTag("property");'."\n".
								t(4).'}'."\n".
								t(4).'$xml->endTag("properties");'."\n".
								t(4).'$xml->endTag("action");'."\n".
							t(3).'}'."\n".
							t(3).'$xml->endTag("actions");'."\n\n".							
							t(3).'$xml->endTag("controller");'."\n".
						t(2).'}'."\n".
						t(2).'$xml->endTag("controllers");'."\n\n".						
						t(2).'$xml->endTag("langs");'."\n".				        
				        t(2).'$this->saveXML($xml);';
			
			$next =		t(1).'public function getLangProperties($file,$langs)'."\n".	
						t(1).'{'."\n".	
							t(2).'$properties = array();'."\n\n".								
							t(2).'foreach($langs as $lang)'."\n".	
							t(2).'{'."\n".	
								t(3).'$fileN = $file.".".$lang.".lang.php";'."\n".
								t(3).'$properties_{$lang} = array();'."\n\n".								
								t(3).'if (file_exists($fileN))'."\n".
								t(3).'{'."\n".
									t(4).'$fileExploded = explode("\n",file_get_contents($fileN));'."\n".
									t(4).'array_map("trim",$fileExploded);'."\n\n".									
									t(4).'foreach($fileExploded as $line)'."\n".
									t(4).'{'."\n".
										t(5).'$line = trim($line);'."\n".
										t(5).'if (SLS_String::startsWith($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']]\'))'."\n".
										t(5).'{'."\n".
											t(6).'$type = (SLS_String::startsWith($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']][\\\'XSL\\\'][\\\'\')) ? "XSL" : "JS";'."\n".
											t(6).'$end = SLS_String::substrAfterFirstDelimiter($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']][\\\'\'.$type.\'\\\'][\\\'\');'."\n\n".											
											t(6).'$key = SLS_String::substrBeforeFirstDelimiter($end,\'\\\']\');'."\n".
											t(6).'$value = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($end,\'";\'),\'"\');'."\n".
											t(6).'$properties_{$lang}[$key] = $value;'."\n".
										t(5).'}'."\n".
									t(4).'}'."\n".
								t(3).'}'."\n".
							t(2).'}'."\n\n".							
							t(2).'foreach($langs as $lang)'."\n".
								t(3).'foreach($properties_{$lang} as $key => $value)'."\n".
									t(4).'$properties[$key][$lang] = $value;'."\n\n".							
							t(2).'return $properties;'."\n".
						t(1).'}'."\n\n".						
						t(1).'public function setLangProperties($file,$properties,$langs)'."\n".
						t(1).'{'."\n".
							t(2).'foreach($langs as $lang)'."\n".
							t(2).'{'."\n".
								t(3).'$fileN = $file.".".$lang.".lang.php";'."\n\n".											
								t(3).'if (file_exists($fileN))'."\n".
								t(3).'{'."\n".
									t(4).'$newFile = "";'."\n".
									t(4).'$fileExploded = explode("\n",file_get_contents($fileN));'."\n".
									t(4).'array_map("trim",$fileExploded);'."\n".
									t(4).'$endFound = false;'."\n\n".									
									t(4).'foreach($fileExploded as $line)'."\n".
									t(4).'{'."\n".
										t(5).'if (!$endFound)'."\n".
										t(5).'{'."\n".
											t(6).'$line = trim($line);'."\n\n".											
											t(6).'if (SLS_String::startsWith($line,\'?>\'))'."\n".
												t(7).'$endFound = true;'."\n\n".											
											t(6).'if (SLS_String::startsWith($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']]\'))'."\n".
											t(6).'{'."\n".
												t(7).'$type = (SLS_String::startsWith($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']][\\\'XSL\\\'][\\\'\')) ? "XSL" : "JS";'."\n".
												t(7).'$end = SLS_String::substrAfterFirstDelimiter($line,\'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']][\\\'\'.$type.\'\\\'][\\\'\');'."\n".
												t(7).'$key = SLS_String::substrBeforeFirstDelimiter($end,\'\\\']\');'."\n\n".												
												t(7).'if (!empty($properties[$lang][$key]))'."\n".
													t(8).'$newFile .= \'$GLOBALS[$GLOBALS[\\\'PROJECT_NAME\\\']][\\\'\'.$type.\'\\\'][\\\'\'.$key.\'\\\'] = "\'.str_replace(\'"\',\'\"\',$properties[$lang][$key]).\'";\';'."\n".
												t(7).'else'."\n".
													t(8).'$newFile .= $line;'."\n".
											t(6).'}'."\n".
											t(6).'else'."\n".
												t(7).'$newFile .= $line;'."\n\n".																
											t(6).'if (!$endFound)'."\n".
												t(7).'$newFile .= "\n";'."\n".
										t(5).'}'."\n".
									t(4).'}'."\n".
									t(4).'file_put_contents($fileN,$newFile);'."\n".
								t(3).'}'."\n".
							t(2).'}'."\n".
						t(1).'}'."\n";  
				      
			$source = substr($source,0,strpos($source,"action()")+8)."\n".
					  t(1).'{'."\n".
					  $action."\n".
					  t(1).'}'."\n\n".
					  $next.
					  '}'."\n".
					  '?>';
			file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Translation.controller.php",$source);			
			
			$sourceXsl = 	'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
						 	t(1).'<xsl:template name="Translation">'."\n".
							 	t(2).'<xsl:call-template name="BoMenu" />'."\n".
								t(2).'<style>'."\n".
									t(3).'input[type="text"], table, textarea {'."\n".
										t(4).'width:100%;'."\n".
									t(3).'}'."\n".
								t(2).'</style>'."\n".
								t(2).'<h1>Project Translations</h1>'."\n\n".							
								t(2).'<!-- Global Translations (site.tld.lang.php) -->'."\n".
								t(2).'<xsl:if test="count(//View/langs/site/properties/property) &gt; 0">'."\n".
									t(3).'<h3>Global Translations</h3>'."\n".
									t(3).'<form action="" method="post">'."\n".
										t(4).'<input type="hidden" name="reload_translate" value="true" />'."\n".
										t(4).'<input type="hidden" name="target_id" value="site" />'."\n".
										t(4).'<table class="bo_table_visible" style="margin-top:0" id="site">'."\n".
											t(5).'<tr class="summary">'."\n".
												t(6).'<th style="width:300px;">Label</th>'."\n".
												t(6).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
													t(7).'<th>Language \'<xsl:value-of select="." />\'</th>'."\n".
												t(6).'</xsl:for-each>'."\n".
											t(5).'</tr>'."\n".
											t(5).'<xsl:for-each select="//View/langs/site/properties/property">'."\n".
												t(6).'<tr>'."\n".
													t(7).'<td><xsl:value-of select="name" /></td>'."\n".
													t(7).'<xsl:variable name="position" select="position()" />'."\n".
													t(7).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
													t(8).'<xsl:variable name="lang" select="." />'."\n".
														t(8).'<td>'."\n".
															t(9).'<xsl:if test="//View/langs/site/properties/property[$position]/values/value[lang=$lang]/type = \'input\'">'."\n".
																t(10).'<input type="text" name="{concat(\'LG_\',$lang,\'_\',//View/langs/site/properties/property[$position]/name)}" value="{//View/langs/site/properties/property[$position]/values/value[lang=$lang]/name}" />'."\n".
															t(9).'</xsl:if>'."\n".
															t(9).'<xsl:if test="//View/langs/site/properties/property[$position]/values/value[lang=$lang]/type = \'textarea\'">'."\n".
																t(10).'<textarea rows="5" name="{concat(\'LG_\',$lang,\'_\',//View/langs/site/properties/property[$position]/name)}">'."\n".
																	t(11).'<xsl:value-of select="//View/langs/site/properties/property[$position]/values/value[lang=$lang]/name" />'."\n".
																t(10).'</textarea>'."\n".
															t(9).'</xsl:if>'."\n".
														t(8).'</td>'."\n".
													t(7).'</xsl:for-each>'."\n".
												t(6).'</tr>'."\n".
											t(5).'</xsl:for-each>'."\n".
										t(4).'</table>'."\n".
										t(4).'<input type="submit" value="Update" />'."\n".
									t(3).'</form>'."\n".
								t(2).'</xsl:if>'."\n".
								t(2).'<!-- /Global Translations (site.tld.lang.php) -->'."\n\n".							
								t(2).'<!-- Controllers Translations -->'."\n".
								t(2).'<h3>Controllers Translations</h3>'."\n".
								t(2).'<xsl:for-each select="//View/langs/controllers/controller">'."\n".
									t(3).'<xsl:variable name="positionC" select="position()" />'."\n".
									t(3).'<xsl:if test="count(properties/property) &gt; 0 or count(actions/action) &gt; 0">'."\n".
										t(4).'<h5>Controller \'<xsl:value-of select="name" />\'</h5>'."\n".
										t(4).'<xsl:if test="count(properties/property) = 0">'."\n".
											t(5).'This Controller haven\'t yet any language properties.'."\n".
										t(4).'</xsl:if>'."\n".
										t(4).'<xsl:if test="count(properties/property) &gt; 0">'."\n".
											t(5).'<form action="" method="post">'."\n".
												t(6).'<input type="hidden" name="reload_translate" value="true" />'."\n".
												t(6).'<input type="hidden" name="target_id" value="{id}" />'."\n".
												t(6).'<table class="bo_table_visible" style="margin-top:0" id="{id}">'."\n".
													t(7).'<tr class="summary">'."\n".
														t(8).'<th style="width:300px;">Label</th>'."\n".
														t(8).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
															t(9).'<th>Language \'<xsl:value-of select="." />\'</th>'."\n".
														t(8).'</xsl:for-each>'."\n".
													t(7).'</tr>'."\n".
													t(7).'<xsl:for-each select="properties/property">'."\n".
														t(8).'<tr>'."\n".
															t(9).'<td><xsl:value-of select="name" /></td>'."\n".
															t(9).'<xsl:variable name="position" select="position()" />'."\n".
															t(9).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
																t(10).'<xsl:variable name="lang" select="." />'."\n".
																t(10).'<td>'."\n".
																	t(11).'<xsl:if test="//View/langs/controllers/controller[$positionC]/properties/property[$position]/values/value[lang=$lang]/type = \'input\'">'."\n".
																		t(12).'<input type="text" name="{concat(\'LG_\',$lang,\'_\',//View/langs/controllers/controller[$positionC]/properties/property[$position]/name)}" value="{//View/langs/controllers/controller[$positionC]/properties/property[$position]/values/value[lang=$lang]/name}" />'."\n".
																	t(11).'</xsl:if>'."\n".
																	t(11).'<xsl:if test="//View/langs/controllers/controller[$positionC]/properties/property[$position]/values/value[lang=$lang]/type = \'textarea\'">'."\n".
																		t(12).'<textarea rows="5" name="{concat(\'LG_\',$lang,\'_\',//View/langs/controllers/controller[$positionC]/properties/property[$position]/name)}">'."\n".
																			t(13).'<xsl:value-of select="//View/langs/controllers/controller[$positionC]/properties/property[$position]/values/value[lang=$lang]/name" />'."\n".
																		t(12).'</textarea>'."\n".
																	t(11).'</xsl:if>'."\n".
																t(10).'</td>'."\n".
															t(9).'</xsl:for-each>'."\n".
														t(8).'</tr>'."\n".
													t(7).'</xsl:for-each>'."\n".
												t(6).'</table>'."\n".
												t(6).'<input type="submit" value="Update" />'."\n".
											t(5).'</form>'."\n".
										t(4).'</xsl:if>'."\n\n".										
										t(4).'<!-- Actions Translations -->'."\n".
										t(4).'<xsl:if test="count(actions/action) = 0">'."\n".
											t(5).'This Controller haven\'t yet any actions.'."\n".
										t(4).'</xsl:if>'."\n".
										t(4).'<xsl:if test="count(actions/action) &gt; 0">'."\n".
											t(5).'<div style="margin-left:40px;">'."\n".
												t(6).'<h5>Actions</h5>'."\n".
												t(6).'<xsl:for-each select="actions/action">'."\n".
													t(7).'<xsl:variable name="positionA" select="position()" />'."\n".
													t(7).'<fieldset style="display:block;">'."\n".
														t(8).'<legend>Action \'<xsl:value-of select="name" />\'</legend>'."\n".
														t(8).'<xsl:if test="count(properties/property) = 0">'."\n".
															t(9).'This Action haven\'t yet any language properties.'."\n".
														t(8).'</xsl:if>'."\n".
														t(8).'<xsl:if test="count(properties/property) &gt; 0">'."\n".
															t(9).'<form action="" method="post">'."\n".
																t(10).'<input type="hidden" name="reload_translate" value="true" />'."\n".
																t(10).'<input type="hidden" name="target_id" value="{id}" />'."\n".
																t(10).'<table class="bo_table_visible" style="margin-top:0" id="{id}">'."\n".
																	t(11).'<tr class="summary">'."\n".
																		t(12).'<th style="width:300px;">Label</th>'."\n".
																		t(12).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
																			t(13).'<th>Language \'<xsl:value-of select="." />\'</th>'."\n".
																		t(12).'</xsl:for-each>'."\n".
																	t(11).'</tr>'."\n".
																	t(11).'<xsl:for-each select="properties/property">'."\n".
																		t(12).'<tr>'."\n".
																			t(13).'<td><xsl:value-of select="name" /></td>'."\n".
																			t(13).'<xsl:variable name="position" select="position()" />'."\n".
																			t(13).'<xsl:for-each select="//Statics/Sls/Configs/site/langs/name" >'."\n".
																				t(14).'<xsl:variable name="lang" select="." />'."\n".
																				t(14).'<td>'."\n".
																					t(15).'<xsl:if test="//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/values/value[lang=$lang]/type = \'input\'">'."\n".
																						t(16).'<input type="text" name="{concat(\'LG_\',$lang,\'_\',//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/name)}" value="{//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/values/value[lang=$lang]/name}" />'."\n".
																					t(15).'</xsl:if>'."\n".
																					t(15).'<xsl:if test="//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/values/value[lang=$lang]/type = \'textarea\'">'."\n".
																						t(16).'<textarea rows="5" name="{concat(\'LG_\',$lang,\'_\',//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/name)}">'."\n".
																							t(17).'<xsl:value-of select="//View/langs/controllers/controller[$positionC]/actions/action[$positionA]/properties/property[$position]/values/value[lang=$lang]/name" />'."\n".
																						t(16).'</textarea>'."\n".
																					t(15).'</xsl:if>'."\n".
																				t(14).'</td>'."\n".
																			t(13).'</xsl:for-each>'."\n".
																		t(12).'</tr>'."\n".
																	t(11).'</xsl:for-each>'."\n".
																t(10).'</table>'."\n".
																t(10).'<input type="submit" value="Update" />'."\n".
															t(9).'</form>'."\n".
														t(8).'</xsl:if>'."\n".
													t(7).'</fieldset>'."\n".
												t(6).'</xsl:for-each>'."\n".
											t(5).'</div>'."\n".
										t(4).'</xsl:if>'."\n".
										t(4).'<!-- /Actions Translations -->'."\n\n".										
									t(3).'</xsl:if>'."\n".
								t(2).'</xsl:for-each>'."\n".
								t(2).'<!-- /Controllers Translations -->'."\n\n".							
								t(2).'<!-- Focus -->'."\n".
								t(2).'<xsl:if test="count(//View/langs/target_id) &gt; 0">'."\n".
									t(3).'<script type="text/javascript">'."\n".
										t(4).'window.location = \'#<xsl:value-of select="//View/langs/target_id" />\';'."\n".
									t(3).'</script>'."\n".
								t(2).'</xsl:if>'."\n".
								t(2).'<!-- /Focus -->'."\n".
							t(1).'</xsl:template>'."\n".
							'</xsl:stylesheet>';
			file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/Translation.xsl",$sourceXsl);
			$this->_generic->goDirectTo("SLS_Bo","Bo");
		}
		
		$xml->addFullTag("url_add_controller",$this->_generic->getFullPath("SLS_Bo","AddController",array(0=>array("key"=>"isBo","value"=>"true"))),true);
		$this->saveXML($xml);
	}
}
?>